<?php
/**
 *	@author wyl
 *	@date 2015-10-29 10:16:01
 */
Yii::import('application.components.autobid.*');
Yii::import('application.components.cronjob.class.*');
Yii::import('dao.bidAuction.*');
Yii::import('application.components.auctionCache.*');
Yii::import('application.components.auctionCache.customerCacheAuctionBidInfo');
class AutoBidCommand extends Cronjob{
	public function runBase(){
		$autoBid=new AutoBidDao();
		$bidAuction=new BidAuction();
		$bidAuction->setEnv('autoBid');
		$customerList=$autoBid->getAutoBidList();
		if(empty($customerList)){
			return false;
		}
		foreach ($customerList as $auction=>$customers){
			foreach ($customers as $customer){
				$autoBid->setPrimaryKey($auction, $customer);
				$bidAuction->customerId=$customer;
				$bidAuction->auctionId=$auction;
				$bidResult=$bidAuction->bid();
				if($bidResult){
					$autoBid->subAmount();
					$autoBid->setSort();
					$customerBidInfoCache=new customerCacheAuctionBidInfo();
					$customerBidInfoCache->customerId=$customer;
					$customerBidInfoCache->auctionId=$auction;
					$customerBidInfoCache->addItem('autobid',$autoBid->getAmount());
					break;
				}else{
					$error=$bidAuction->getErrors();
					$autoBid->addErrorLog();
					if(array_key_exists('is_winner',$error)){
						$this->setSort();
					}else{
						$autoBid->delAutoBid();
					}
				}		
			}
		}
		
	}
}